package com.jiaz.algorithm.threadPool;

import com.jiaz.pojo.UserCheckInFreq;

import java.util.concurrent.CountDownLatch;

/**
 * @author jiajiazi
 * @version 1.0
 * @date 2022/5/3 9:24
 */
public class UserPostionFreqThread implements Runnable {
    private final int sig;
    private final UserCheckInFreq[] arr;
    private final CountDownLatch countDownLatch;

    public UserPostionFreqThread(int sig, UserCheckInFreq[] arr, CountDownLatch countDownLatch) {
        this.sig = sig;
        this.arr = arr;
        this.countDownLatch = countDownLatch;
    }

    @Override
    public void run() {
        if (sig % 2 == 0) {
            for (int i = 0; i < arr.length; i += 2) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("偶数" + i);
                //arr[i] = 10;
            }
            countDownLatch.countDown();
        } else {
            for (int i = 1; i < arr.length; i += 2) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("奇数" + i);
                //arr[i] = 11;
            }
            countDownLatch.countDown();
        }
    }
}
